package cn.parllay.dingdangproject.utils;

import io.netty.channel.socket.SocketChannel;

/**
 * Created by sunny on 2018/1/18.
 */

public class SocketChanelManager {

    private static SocketChanelManager mInstance = null;
    private SocketChannel socketChannel;

    public static SocketChanelManager getInstance() {
        if (mInstance == null) {
            synchronized (SocketChanelManager.class) {
                if (mInstance == null) {
                    mInstance = new SocketChanelManager();
                }
            }
        }
        return mInstance;
    }

    public void setSocketChannel(SocketChannel socketChannel) {
        this.socketChannel = socketChannel;
    }

    public void writeToServer(Object message) {
        if (socketChannel != null) {
            socketChannel.writeAndFlush(message);
        }
    }
}
